#include <iostream>
#include <sstream>

using namespace std;

template <typename T, typename U>
class Pair {
private:
    T first;
    U second;

public:
    Pair(T t, U u) {
        this->first = t;
        this->second = u;
    }

    T getFirst() { return this->first; }

    U getSecond() { return this->second; }
};

template <typename Type>
Type castString(const string &str) {
    istringstream iss(str);
    Type num;
    iss >> num;
    return num;
}

int main(int argc, char const *argv[]) {
    int count;
    cin >> count;
    string type1, type2, value1, value2;

    for (int i = 0; i < count; ++i) {
        cin >> type1 >> type2 >> value1 >> value2;
        if (type1 == "int" and type2 == "double") {
            Pair<int, double> a(castString<int>(value1),
                                castString<double>(value2));
            cout << a.getSecond() << " " << a.getFirst() << endl;
        } else if (type1 == "int" and type2 == "string") {
            Pair<int, string> a(castString<int>(value1), value2);
            cout << a.getSecond() << " " << a.getFirst() << endl;
        } else if (type1 == "double" and type2 == "string") {
            Pair<double, string> a(castString<double>(value1), value2);
            cout << a.getSecond() << " " << a.getFirst() << endl;
        }
    }
    return 0;
}